package com.ft.oa.web.development;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ft.oa.domain.development.ProductCompetitor;
import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.service.development.ProductCompetitorService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 竞品
 */
@RestController
@RequestMapping("/product/competitor")
public class ProductCompetitorController {

    @Resource
    private ProductCompetitorService productCompetitorService;

    /**
     * 添加竞品
     * @param productCompetitor
     * @return
     */
    @PostMapping("/add")
    public ApiResult add(@RequestBody ProductCompetitor productCompetitor){

        productCompetitorService.add(productCompetitor);

        return ApiResult.simpleSuccess();
    }

    /**
     * 修改竞品
     * @param productCompetitor
     * @return
     */
    @PostMapping("/update")
    public ApiResult update(@RequestBody ProductCompetitor productCompetitor){

        productCompetitorService.update(productCompetitor);

        return ApiResult.simpleSuccess();
    }

    /**
     * 删除竞品
     * @return
     */
    @PostMapping("/del")
    public ApiResult del(@RequestBody ProductCompetitor competitor){

        productCompetitorService.del(competitor.getId());
        return ApiResult.simpleSuccess();
    }

    /**
     * 条件分页
     * @return
     */
    @PostMapping("/page")
    public ApiResult page(@RequestBody ProductCompetitor competitor){

        Page<ProductCompetitor> result = productCompetitorService.page(competitor);
        return ApiResult.successWithData(result);
    }
}
